<?php
class MyRules
{
    // note this is a static method
    public static function _validation_unique($val, $options)
    {
        list($table, $field) = explode('.', $options);

        $result = DB::select("LOWER (\"$field\")")
        ->where($field, '=', Str::lower($val))
        ->from($table)->execute();
        return ! ($result->count() > 0);
    }
    
    //kiem tra lieu khi update,co bi trung gia tri voi cac truong khac khong...o day truyen id de loai truong hop trung voi chinh minh
    //vi du khi update username thi username phai ko dc trung voi username khac tru chinh minh
    public static function _validation_unique1($val, $options)
    {
        list($table, $field,$id,$val1) = explode('.', $options);
        $result = DB::query("SELECT '$field' FROM '$table' WHERE '$field'='$val' and '$id' != '$val1'");
        return ! ($result->count() > 0);
    }
    
    // note this is a non-static method
    public function _validation_is_upper($val)
    {
        return $val === strtoupper($val);
    }

}

